const FormData = require('form-data');
const fs = require('fs');
const http = require('http');

function testImport() {
  const form = new FormData();
  
  // 添加文件
  form.append('files', fs.createReadStream('test-script-utf8.sql'));
  
  // 添加其他字段
  form.append('created_by', 'test_user');
  
  const options = {
    hostname: 'localhost',
    port: 3000,
    path: '/api/scripts/import',
    method: 'POST',
    headers: form.getHeaders()
  };
  
  const req = http.request(options, (res) => {
    let data = '';
    
    res.on('data', (chunk) => {
      data += chunk;
    });
    
    res.on('end', () => {
      try {
        const result = JSON.parse(data);
        console.log('Import result:', JSON.stringify(result, null, 2));
      } catch (error) {
        console.log('Raw response:', data);
      }
    });
  });
  
  req.on('error', (error) => {
    console.error('Error testing import:', error.message);
  });
  
  form.pipe(req);
}

testImport();